class BloodWatcherController extends UTBot;

var Actor Destination;
var Pawn thePlayer;

var Vector vect;
var float perceptionDistance;
var float DistanceToPlayer;
var float attackDistance;

protected event ExecuteWhatToDoNext()
{
}

auto state Roaming
{
	event seePlayer(Pawn SeenPlayer)
	{
		if(thePlayer == none)
			thePlayer = SeenPlayer;
		DistanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
		if(DistanceToPlayer < perceptionDistance)
		{
			GotoState('Chasing');
			`log("Switching to Chasing State");
			Worldinfo.Game.Broadcast(self, "Switching to Chase state!!");
		}
	}

Begin:
   //If we just began or we have reached the Destination
   //pick a new destination - at random
	`log("checking destinations");
   if(Destination == none || Pawn.ReachedDestination(Destination))
   {
		// FindRandomDest() is a UDK function in the Controller.uc
		// cant be edited
      Destination = FindRandomDest();
	  `log("dest found");
   }

   //Find a path to the destination and move to the next node in the path
   MoveToward(FindPathToward(Destination), FindPathToward(Destination));

   //fire off next decision loop
   LatentWhatToDoNext();
}

state Chasing
{
Begin:
	Worldinfo.Game.Broadcast(self, "I can see you!!");
	while(Pawn != none && thePlayer.Health > 0)
	{	
		DistanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
		////Find a path to the destination and move to the next node in the path
		if(DistanceToPlayer < attackDistance)
		{
			Worldinfo.Game.Broadcast(self, "Switching to Attack state!!");
		 	GotoState('MeleeAttack');
		//	`log("Switching to the Attack State");
			break;
		}
		else
		{
			Worldinfo.Game.Broadcast(self, "I'm chasing you!!");
			MoveToward(thePlayer, thePlayer);
		}
		Sleep(1);
	}
	//fire off next decision loop
	LatentWhatToDoNext();
}

state MeleeAttack
{
Begin:
	Pawn.Acceleration=vect(0,0,0);
	while(Pawn != none && thePlayer.Health > 0)
	{
		Worldinfo.Game.Broadcast(self, "Going to Attack!!");
		DistanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
		//Find a path to the destination and move to the next node in the path
		if(DistanceToPlayer > attackDistance * 2)
		{
			Worldinfo.Game.Broadcast(self, "Switching back to Chase state!!");
			GotoState('Chasing');
			break;
		}
		else
		{
			Worldinfo.Game.Broadcast(self, "Dealing Dmg!!");
			
		}
		Sleep(1);
	}
   //fire off next decision loop
   LatentWhatToDoNext();
}

defaultproperties
{
	CombatStyle = 1;
	perceptionDistance = 500;
	attackDistance = 100;
}
